#include<bits/stdc++.h>
using namespace std;
int T;
int n,m,L,xs,cnt;
int d[100050],v[100050],a[100050],p[100050];
struct N{
	int z,y;
};
N dd[100050];
bool cmp(N a,N b){
	if(a.y!=b.y)return a.y<b.y;
	else return a.z<b.z;
}
bool chk(int now,int cur){
	if(p[cur]<d[now])return false;
	long long sum=1LL*v[now]*v[now]+2LL*a[now]*(p[cur]-d[now]);
	if(sum>1LL*xs*xs)return true;
	return false;
}
int main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>T;
	while(T--){
		cnt=0;
		cin>>n>>m>>L>>xs;
		for(int i=1;i<=n;i++){
			cin>>d[i]>>v[i]>>a[i];
		}
		for(int i=1;i<=m;i++)cin>>p[i];
		sort(p+1,p+1+m);
		for(int i=1;i<=n;i++){
			if(a[i]==0){
				if(v[i]>xs&&d[i]<=p[m]){
					cnt++;
					int zz=1,yy=m,mb=-1;
					while(zz<=yy){
						int mid=(zz+yy)/2;
						if(p[mid]>=d[i]){
							mb=mid;
							yy=mid-1;
						}
						else zz=mid+1;
					}
					dd[cnt].z=mb;
					dd[cnt].y=m;
				}
			}
			if(a[i]>0){
				int l=1,r=m,ans=-1;
				while(l<=r){
					int mid=(l+r)>>1;
					if(chk(i,mid)){
						ans=mid;
						r=mid-1;
					}
					else l=mid+1;
				}
				if(ans==-1)continue;
				else{
					cnt++;
					dd[cnt].z=ans;
					dd[cnt].y=m;
				}
			}
			if(a[i]<0){
				int zz=1,yy=m,mb=-1;
				while(zz<=yy){
					int mid=(zz+yy)/2;
					if(p[mid]>=d[i]){
						mb=mid;
						yy=mid-1;
					}
					else zz=mid+1;
				}
				if(chk(i,mb)==false||mb==-1)continue;
				else cnt++;
				int l=mb,r=m,ans=-1;
				while(l<=r){
					int mid=(l+r)/2;
					if(chk(i,mid)){
						ans=mid;
						l=mid+1;
					}
					else r=mid-1;
				}
				dd[cnt].z=mb;
				dd[cnt].y=ans;
			}
		}
		cout<<cnt<<' ';
		sort(dd+1,dd+1+cnt,cmp);
		int last=-1;
		int res=m;
		for(int i=1;i<=cnt;i++){
			if(dd[i].z>last){
				res--;
				last=dd[i].y;
			}
		}
		cout<<res<<'\n';
	}
	return 0;
}
